<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>CareNote-UserUpdate</title>
    <link rel="stylesheet" type="text/css" href="../../../static/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="../../../static/css/add.css"/>
</head>
<style>
    .light {
        font-size: 20px;
        color: #fefefe;
        text-shadow: 0 0 0.5em #0ae642, 0 0 0.2em #5c5c5c;
    }
</style>
<body>
<div id="app" class="light" style="text-align:center;">
    <div class="header">
        <span>修改普通用户</span>
    </div>
    <div class="content" >
        <table >
            <tr>
                <td class="text-right">邮箱</td>
                <td class="content_right"><input class="input inline-input" id="userEmail" placeholder="请输入Email"> <span
                        class="btn btn-info" id="findByPhone">立即查找</span></td>
            </tr>
        </table>
    </div>
    <div class="header">
        <span>查找信息如下</span>
    </div>
    <div class="content" >
        <table>
            <tr>
                <td class="text-right">该用户信息</td>
                <td class="content_right"><label>
                    <input disabled="disabled" class="input" id="name">
                    <input readOnly="readOnly" class="input" id="id">
                </label>
                </td>
            </tr>
            <tr>
                <td class="text-right">备注</td>
                <td class="content_right"><label>
                    <input class="input" id="bz" placeholder="请输入备注">
                </label></td>
            </tr>
            <tr>
                <td class="text-right">邮箱</td>
                <td class="content_right"><label>
                    <input class="input" id="email" placeholder="请输入邮箱">
                </label></td>
            </tr>
            <tr>
                <td class="text-right">密码</td>
                <td class="content_right"><label>
                    <input class="input" id="pwd" placeholder="请输入密码">
                </label></td>
            </tr>
            <tr>
                <td class="text-right">权限</td>
                <td class="content_right"><label>
                   <select id="power" class="input" >
                       <option value="1">普通用户</option>
                       <option value="2">2-级用户</option>
                       <option value="3">接受提醒用户</option>
                       <option value="0">停用</option>
                       <option value="-1">删除</option>
                       <option value="4">普通管理员</option>
                   </select>
                </label></td>
            </tr>
            <tr>
                <td></td>
                <td class="content_right">
                    <span class="btn btn-info" id="user_update">立即修改</span>
                    <span class="btn">重置</span></td>
            </tr>
        </table>
    </div>
</div>
</body>
<script src="../../../static/js/jquery2.1.4.js"></script>
<script src="../../../static/layer/layer.js"></script>
<script>
    $(".header:eq(1),.content:eq(1)").hide();
    let userId = null;
    $(function () {
        $("#findByPhone").click(function () {
            const uEmail = $.trim($("#userEmail").val());
            if (uEmail===""||uEmail.length===0){
                layer.msg("查询信息不能为空！");
                return;
            }
            const windowId = layer.load();
            $.getJSON("/admin/user", {email: uEmail}, function (data) {
                layer.close(windowId);
                //data:{"status":0,"result":"查询成功","data":{"id":2,"number":"124","username":"张三","userPhone":"13843838438","company":"京东快递","code":"213456","inTime":"Jul 21, 2020, 4:26:21 PM","status":0,"sysPhone":"18888888888"}}
                layer.msg(data.result);
                if (data.status === 200) {
                    $(".header:eq(1),.content:eq(1)").fadeIn(1000);
                    var u = data.data;
                    $("#name").val(u.name);
                    $("#id").val(u.id);
                    $("#bz").val(u.bz);
                    $("#email").val(u.email);
                    $("#pwd").val(u.pwd);
                    $("#power").val(u.power);
                }
            })
        });
        let emailZZ = /^[A-Za-z0-9-_\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
        $("#user_update").click(function () {
            var id = $("#id").val();
            var bz = $.trim($("#bz").val());
            var email = $.trim($("#email").val());
            var pwd = $.trim($("#pwd").val());
            var power = $.trim($("#power").val());
            if(pwd===""||pwd.length===0||power===""||power.length===0){
                layer.msg("注意：邮箱、密码、权限均不可为空！");
                return ;
            }
            if (bz.length>50||pwd>20){
                layer.msg("乖，备注不可超过50字，密码不可超过20字！");
                return ;
            }
            if (!emailZZ.test(email)){
                layer.msg("请输入有效邮箱！");
                return ;
            }
            const windowId = layer.load();
            $.post("/admin/user", {
                id:id,bz:bz,email:email,pwd:pwd,power:power
            }, function (data) {
                layer.close(windowId);
                layer.msg(data.result);
                if (data.status === 0) {
                    //修改成功
                    $("input").val("");
                } else {
                    //失败
                }
            });

            return false;
        });
    });
</script>
</html>
